package com.wc.算法基础课.B第二讲数据结构.并查集.网络分析;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/3/20 21:03
 * @description https://www.acwing.com/activity/content/problem/content/9796/
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 200010, M = N >> 1;
    static int[] h = new int[N];
    static int[] e = new int[M];
    static int[] ne = new int[M];
    static int idx = 1;
    static int[] f = new int[N];
    static int[] p = new int[N];
    static int n, m, q, a, b;

    static void add(int a, int b) {
        e[idx] = b;
        ne[idx] = h[a];
        h[a] = idx++;
    }

    static int find(int x) {
        if (p[x] != x) p[x] = find(p[x]);
        return p[x];
    }

    static void dfs(int u, int fa) {
        f[u] += f[fa];
        for (int i = h[u]; i > 0; i = ne[i]) {
            int j = e[i];
            dfs(j, u);
        }
    }

    public static void main(String[] args) {
        n = sc.nextInt();
        m = sc.nextInt();
        int root = n + 1;
        for (int i = 1; i <= 2 * n; i++) p[i] = i;
        while (m-- > 0) {
            q = sc.nextInt();
            a = sc.nextInt();
            b = sc.nextInt();
            if (q == 1) {
                a = find(a);
                b = find(b);
                if (a != b) {
                    p[a] = p[b] = root;
                    add(root, a);
                    add(root, b);
                    root++;
                }
            } else {
                a = find(a);
                f[a] += b;
            }
        }

        for (int i = n + 1; i < root; i++) {
            if (p[i] == i) dfs(i, 0);
        }
        for (int i = 1; i <= n; i++) {
            out.print(f[i] + " ");
        }
        out.println();
        out.flush();
    }

}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
